<%--
  Created by IntelliJ IDEA.
  User: WuLianFa
  Date: 2018/5/22 0022
  Time: 上午 10:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="utf-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://jsptags.com/tags/navigation/pager" prefix="pg" %>
<%@ taglib uri="http://shiro.apache.org/tags" prefix="shiro" %>
<%
    request.setCharacterEncoding("UTF-8");
    String path = request.getContextPath();
%>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>物品信息管理</title>
    <link href="<%=path%>/CSS/style.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="<%=path%>/JQuery/jquery-1.8.2.js"></script>
    <script type="text/javascript" src="<%=path%>/My97DatePicker/WdatePicker.js"></script>
    <%@ include file="/WEB-INF/JSP/ajax.jsp" %>
    <script type="text/javascript" src="<%=path%>/HoganJS/handlebars-v4.0.11.js"></script>
    <style type="text/css">
        .seachform li label {
            line-height: 45px;
            color: #444444
        }

        .scinput {
            line-height: 10px;
            margin-top: 5px
        }

        .scinput1 {
            margin-top: 5px;
            height: 30px;
        }

        .scbtn {
            background: #57a0ff;
            border-radius: 20px;
            width: 110px;
            margin-top: 4px;
            height: 35px
        }

        .scbtn2 {
            height: 20px;
            background: #57a0ff;
            border-radius: 20px;
            width: 50px;
            color: #fff;
            display: none;
        }

        .tablelist {
            border: none;
            margin: 10px 20px
        }

        .tablelist th {
            background: none;
            border-bottom: none;
        }

        thead {
            background: #f2f2f2
        }

        tbody tr:nth-child(even) {
            background: #f7f8fd
        }

        .tablelist th {
            height: 45px;
            padding-left: 30px
        }

        .tablelist td {
            border-right: none;
            padding-left: 30px
        }

        tbody tr {
            height: 38px
        }

        .check {
            padding-left: 0px
        }

        a {
            cursor: pointer;
        }

        .tablelist {
            width: 500px;
            border: 0px;
            border-collapse: collapse;
            border-spacing: 0;
        }

        .tablelist tr {
            height: 30px;
        }

        .tablelist tr td {
            border-bottom: 1px solid #BBB;
        }
    </style>
</head>
<body style="background: #f5f5f5;padding: 0 10px;">
<div class="place" style="background: #f5f5f5;margin-top: 10px">
    <ul class="placeul">
        <li><a href="#">仓库管理</a></li>
        <li><a href="#">物品管理</a></li>
    </ul>
</div>

<div class="rightinfo" style="background: #fff;border-radius:10px;height: 45px;">
    <ul class="seachform">
        <li><label>物品名称</label><input id="goodsName" type="text" name="goodsName" class="scinput"/></li>
        <li><label>物品类型</label><input id="goodsType" type="text" name="goodsType" class="scinput"/></li>
        <li><label>物品规格</label><input id="goodsGgid" type="text" name="goodsGgid" class="scinput"/></li>
        <li><label>&nbsp;</label><input type="button" class="scbtn"
                                        onclick="goodsAllMassageListPaging()" value="立即查询"/></li>
    </ul>
</div>


<div style="width: 100%;overflow:auto;margin-bottom: 0px;margin-top: 30px;background: #fff;border-radius:10px;box-shadow: 0 0 10px #f2f2f2;margin-bottom: 20px;min-height: 600px">
    <ul>
        <li style="height: 40px;text-align: left;color: #999999;">
				  <span style="font-size: 12px;">
				  <shiro:hasPermission name="/insertCar">
					  <img alt="" style="margin-top: 20px;margin-left: 22px;height: 12px;"
                           src="<%=path%>/images/list/xz.png">
                      &nbsp;<a href="<%=path%>/DrivingSys/jumpToAddGoodsPage">新增</a>
                  </shiro:hasPermission>
				  <shiro:hasPermission name="/deleteCarByFid">
					  <img alt="" style="margin-top: 20px;margin-left: 22px;height: 12px;"
                           src="<%=path%>/images/list/sc.png">
                      &nbsp;<a class="del">删除</a>
                  </shiro:hasPermission>
				 <shiro:hasPermission name="/selectCarByFid">
                     <img alt="" height="11px" src="<%=path%>/images/list/xg.png" style="padding-left: 20px">
                     <a class="modify">修改</a>
                 </shiro:hasPermission>
					  <shiro:hasPermission name="/selectCarByFid">
					  <img alt="" style="margin-top: 20px;margin-left: 22px;height: 12px;width: 14px"
                           src="<%=path%>/images/list/excel.png">
                          &nbsp;<a onclick="exportExcel()">导出Excle</a>
                      </shiro:hasPermission>
				  </span>
        </li>
    </ul>
    <table class="tablelist" style="width: auto;white-space:nowrap;">
        <thead>
        <tr>
            <th><input type="checkbox" class="goodscheckbox"></th>
            <th>物品名称</th>
            <th>物品类型</th>
            <th>规格编号</th>
            <th>物品单价</th>
            <th>创建人</th>
            <th>创建时间</th>
            <th>最后修改人</th>
            <th>最后修改时间</th>
            <th>驾校</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody class="allGoodsListOptionAppendTo">
        <%-- ajax响应内容区--%>
        </tbody>
    </table>
</div>

当前第<a class="currentPage"></a>页&nbsp;
共<a class="trailerPage"></a>页&nbsp;
每页显示<input style="width: 50px;border:0.5px solid #378888" class="pageSize" type="text" placeholder="输入条数"
           onkeydown="EnterPress()"/>条数据&nbsp;
<a href="javascript:void(0)" onclick="fristPage()">[首页]</a>
<a href="javascript:void(0)" onclick="prePage()">上一页</a>
<a href="javascript:void(0)" onclick="nextPage()">下一页</a>
<a href="javascript:void(0)" onclick="endPage()">[尾页]</a>

<div style="height: 30px"></div>
<div id="tip2"></div>
<div class="tip">
    <div class="tiptop">
        <span>提示信息</span>
    </div>
    <div class="tipinfo">
        <span><img src="<%=path%>/images/ticon.png"/></span>
        <div class="tipright">
            <p>是否确认对信息删除 ？</p>
            <cite>如果是请点击确定按钮 ，否则请点取消。</cite>
        </div>
    </div>
    <div class="tipbtn">
        <input name="" type="button" class="sure" value="确定"/>&nbsp; <input
            name="" type="button" class="cancel" value="取消"/>
    </div>
</div>
</body>

<script type="text/javascript">
    //初始化加载
    $(document).ready(function () {
        goodsAllMassageListPaging();
    });

    var trailerPage;//尾页
    var currentPage = 1;
    var pageSize;

    //首页
    function fristPage() {
        currentPage = 1;
        goodsAllMassageListPaging();
    }

    //上一页
    function prePage() {
        currentPage--;
        if (currentPage <= 0) {
            currentPage = 1;
        }
        goodsAllMassageListPaging();
    }

    //下一页
    function nextPage() {
        var tPage = $(".trailerPage").html();
        if (parseInt(tPage) != 0) {
            if (currentPage == trailerPage) {
                currentPage = trailerPage;
            } else {
                currentPage++;
            }
            goodsAllMassageListPaging();
        }
    }

    //尾页
    function endPage() {
        var tPage = $(".trailerPage").html();
        if (parseInt(tPage) != 0) {
            currentPage = trailerPage;
            goodsAllMassageListPaging();
        }
    }

    //输入显示每页数回车刷新数据
    function EnterPress() {
        if (event.keyCode == 13) {
            goodsAllMassageListPaging();
        }
        currentPage = 1;
    }

    //分页
    function goodsAllMassageListPaging() {
        var goodsName = $("#goodsName").val();//要搜索的物品名称
        var goodsType = $("#goodsType").val();//要搜索的物品名称
        var goodsGgid = $("#goodsGgid").val();//要搜索的物品名称
        var pageSizeInput = $(".pageSize").val();//输入的每页显示条数
        if (pageSizeInput != null && pageSizeInput != '') {
            pageSize = parseInt(pageSizeInput);
        } else {
            pageSize = 3;
        }
        $.ajax({
            url: '<%=path%>/DrivingSys/goodsAllMassageListPaging', //请求的url
            type: 'post', //请求的方式
            data: {
                "goodsName": goodsName,
                "goodsType": goodsType,
                "goodsGgid": goodsGgid,
                "currentPage": currentPage,
                "pageSize": pageSize
            },
            success: function (data) {
                trailerPage = data.getLastPage;
                if (data.goodsList == null || data.goodsList == '') {
                    $(".allGoodsListOptionAppendToRemove").remove();
                    var str = "<tr class='allGoodsListOptionAppendToRemove'><th colspan='13'><span>抱歉,没有任何相关的记录信息!</span></th> </tr>";
                    $(".allGoodsListOptionAppendTo").append(str);
                } else {
                    $(".allGoodsListOptionAppendToRemove").remove();
                    for (var i = 0; i < data.goodsList.length; i++) {
                        var str = "<tr class='allGoodsListOptionAppendToRemove' ondblclick='doubleClickTheQuery(\"" + data.goodsList[i].wpId + "\")'><td><input type='checkbox' class='doubleClickTheValue' value='" + data.goodsList[i].wpId + "' name='doubleClickTheValue'/></td><td>" + data.goodsList[i].wpName + "</td> <td>" + data.goodsList[i].wpType + "</td> <td>" + data.goodsList[i].wpGgid + "</td> <td>" + data.goodsList[i].wpPrice + "</td> <td>" + data.goodsList[i].wpCreator + "</td> <td>" + data.goodsList[i].wpCreationtime + "</td> <td>" + data.goodsList[i].wpLastmodifier + "</td> <td>" + data.goodsList[i].wpLastmodificationtime + "</td> <td>" + data.goodsList[i].wpSchoolid + "</td><td><shiro:hasPermission name='/selectCarByFid'> <img alt='' height='11px' src='<%=path%>/images/list/xg.png'> <a href='<%=path%>/DrivingSys/queryGoodsMassage?wpId=" + data.goodsList[i].wpId + "' class='tablelink'>修改</a></shiro:hasPermission><shiro:hasPermission name='/deleteCarByFid'> <img alt='' style='margin-top: 20px;margin-left: 22px;height: 12px;'src='<%=path%>/images/list/sc.png'> &nbsp;<a class='delOne' class='tablelink' style='color: #056dae' onclick='removingAsingle(\"" + data.goodsList[i].wpId + "\")'>删除</a> &nbsp;&nbsp;&nbsp;</shiro:hasPermission> </td></tr>";
                        $(".allGoodsListOptionAppendTo").append(str);
                    }
                }
                $(".trailerPage").html(trailerPage);//总页数赋值
                $(".currentPage").html(currentPage);//当前页赋值
            }
        });
    }

    //设置全选功选
    $('.goodscheckbox').click(function () {
        if ($(this).attr("checked")) {
            $(":checkbox").prop("checked", true)
        } else {
            $('input:checkbox').removeAttr('checked')
        }
    })

    //删除多个
    $('.del').click(function () {
        var findid = document.getElementsByName("doubleClickTheValue");
        var wpid;
        for (var i = 0; i < findid.length; i++) {
            if (findid[i].checked) {
                wpid = findid[i].value;
            }
        }
        if (wpid == null || wpid == "") {
            alert("请至少选择一条数据删除！")
            return false
        } else {
            $(".tip").fadeIn(200);
            $("#tip2").css('visibility', 'visible');
        }
        $(".sure").click(function () {
            $(".tip").fadeOut(100);
            var str = new Array();
            var j = 0;
            for (var i = 0; i < findid.length; i++) {
                if (findid[i].checked) {
                    str[j] = findid[i].value;
                    j++;
                }
            }
            location = '<%=path%>/DrivingSys/deleteGoodsById?wpIdArray=' + str;
        })

        $(".cancel").click(function () {
            $(".tip").fadeOut(100);
            $("#tip2").css('visibility', 'hidden');
        });
    })

    //删除单个
    function removingAsingle(wpId) {
        $("#tip2").css('visibility', 'visible');
        $(".tip").fadeIn(200);
        $(".sure").click(function () {
            location = '<%=path%>/DrivingSys/deleteGoodsById?wpId=' + wpId;
        })

        $(".cancel").click(function () {
            $(".tip").fadeOut(100);
            $("#tip2").css('visibility', 'hidden');
        });
    }

    //修改
    $(".modify").click(function () {
        var stringFid;
        var fids = document.getElementsByName("doubleClickTheValue");
        for (var i = 0; i < fids.length; i++) {
            if (fids[i].checked) {
                stringFid = fids[i].value;
                location = '<%=path%>/DrivingSys/queryGoodsMassage?wpId=' + stringFid;
                return false
            }
        }
        if (stringFid == null || stringFid.length == 0) {
            alert("请至少选择一条数据修改")
            return false
        }
    })

    //查询详情
    function doubleClickTheQuery(wpId) {
        location = '<%=path%>/DrivingSys/queryGoodsMassage?wpId=' + wpId;
    }

    //导出
    function exportExcel() {
        var findid = document.getElementsByName("doubleClickTheValue");
        var wpIdArray = new Array();
        var j = 0;
        for (var i = 0; i < findid.length; i++) {
            if (findid[i].checked) {
                wpIdArray[j] = findid[i].value;
                j++;
            }
        }
        location = '<%=path%>/DrivingSys/exportGoodsMassage?wpIdArray=' + wpIdArray;
    }

</script>
</html>
